package com.css.fxfzaqbz.modules.data.controller;

import com.css.fxfzaqbz.base.response.RestResponse;
import com.css.fxfzaqbz.modules.data.entity.AidedAnalyse;
import com.css.fxfzaqbz.modules.data.service.AidedAnalyseService;
import com.css.fxfzaqbz.modules.data.vo.AidedAnalyseVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 辅助分析
 *
 */
@RestController
@RequestMapping("/fxfzaqbz/data")
@Slf4j
public class AidedAnalyseController {
    @Resource
    AidedAnalyseService aidedAnalyseService;
    /**
     * 新增AidedAnalyse
     * @param aidedAnalyse
     * @return
     */
    @PostMapping("/saveAidedAnalyse")
    public RestResponse saveAidedAnalyse (@RequestBody AidedAnalyse aidedAnalyse){
        RestResponse restResponse = null ;
        try{
            aidedAnalyseService.saveAidedAnalyse(aidedAnalyse);
            restResponse = RestResponse.succeed();
        }catch (Exception e){
            log.error("新增辅助分析数据失败",e);
            restResponse = RestResponse.fail("新增辅助分析数据失败!");
        }
        return restResponse;
    }



    /*
    * 添加多个
    * */
    @PostMapping("/saveAidedAnalyses")
    public RestResponse saveAidedAnalyses (@RequestBody List<AidedAnalyse> aidedAnalyses){
        RestResponse restResponse = null ;
        try{

            aidedAnalyseService.saveAidedAnalyses(aidedAnalyses);
            restResponse = RestResponse.succeed();
        }catch (Exception e){
            log.error("新增辅助分析数据失败",e);
            restResponse = RestResponse.fail("新增辅助分析数据失败!");
        }
        return restResponse;
    }
    /**
     * 根据 id 查询辅助分析数据
     *
     * @param id id
     * @return 辅助分析数据
     */
    @GetMapping("/getAidedAnalyseById/{id}")
    public RestResponse getAidedAnalyseById(@PathVariable String id) {
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(aidedAnalyseService.getAidedAnalyseById(id));
        } catch (Exception e) {
            log.error("查询辅助分析数据失败!", e);
            restResponse = RestResponse.fail("查询辅助分析数据失败");
        }
        return restResponse;
    }

    /**
     * 逻辑删除，修改数据标志位
     *
     * @param ids 辅助分析数据id列表
     * @return
     */
    @PostMapping("/delAidedAnalyse/{ids}")
    public RestResponse delAidedAnalyse(@PathVariable("ids") List<String> ids) {
        RestResponse restResponse = null;
        try {
            aidedAnalyseService.delAidedAnalyse(ids);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("删除辅助分析数据失败!", e);
            restResponse = RestResponse.fail("删除辅助分析数据失败!");
        }
        return restResponse;
    }

    /**
     * 修改辅助分析数据
     * @param aidedAnalyse
     * @return
     */
    @PostMapping("/updateAidedAnalyse")
    public RestResponse updateAidedAnalyse(@RequestBody AidedAnalyse aidedAnalyse) {
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(aidedAnalyseService.updateAidedAnalyse(aidedAnalyse));
        } catch (Exception e) {
            log.error("修改辅助分析数据失败!", e);
            restResponse = RestResponse.fail("修改辅助分析数据失败!");
        }
        return restResponse;
    }

    /**
     * 根据 iaId 查询辅助分析数据-过程稿
     *
     * @param iaId 活动id
     * @return 辅助分析数据
     */
    @GetMapping("/getAidedAnalyseByIaId/{iaId}")
    public RestResponse getAidedAnalyseByIaId(@PathVariable String iaId) {
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(aidedAnalyseService.getAidedAnalyseByIaId(iaId));
        } catch (Exception e) {
            log.error("查询辅助分析数据失败!", e);
            restResponse = RestResponse.fail("查询辅助分析数据失败");
        }
        return restResponse;
    }

    /**
     * 根据 iaId 查询辅助分析数据-最终成果
     *
     * @param iaId 活动id
     * @return 辅助分析数据
     */
    @GetMapping("/getByIaId/{iaId}")
    public RestResponse getByIaId(@PathVariable String iaId) {
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(aidedAnalyseService.getByIaId(iaId));
        } catch (Exception e) {
            log.error("查询辅助分析数据失败!", e);
            restResponse = RestResponse.fail("查询辅助分析数据失败");
        }
        return restResponse;
    }

    /**
     * 添加描述
     * @param aidedAnalyseVo
     * @return
     */
    @PostMapping("/saveDescription")
    public RestResponse saveDescription(@RequestBody AidedAnalyseVo aidedAnalyseVo) {
        RestResponse restResponse = null;
        try {
            aidedAnalyseService.saveDescription(aidedAnalyseVo);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("添加描述失败!", e);
            restResponse = RestResponse.fail("添加描述失败!");
        }
        return restResponse;
    }

    /**
     * 重复校验
     * @param aidedAnalyse
     * @return
     */
    @PostMapping("/check")
    public RestResponse check(@RequestBody AidedAnalyse aidedAnalyse){
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(aidedAnalyseService.check(aidedAnalyse));
        } catch (Exception e) {
            log.error("重复校验失败!", e);
            restResponse = RestResponse.fail("重复校验失败!");
        }
        return restResponse;
    }


    /**
     * 最终成功唯一性校验
     * @param
     * @return
     */
    @GetMapping("/UniquenessCheck/{iaId}")
    public RestResponse UniquenessCheck(@PathVariable("iaId") String iaId){
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(aidedAnalyseService.UniquenessCheck(iaId));
        } catch (Exception e) {
            log.error("重复校验失败!", e);
            restResponse = RestResponse.fail("重复校验失败!");
        }
        return restResponse;
    }


    /**
     * 提交最终成果
     * @param id
     * @return
     */
    @PostMapping("/submitResult")
    public RestResponse submitResult(String id){
        RestResponse restResponse = null;
        try {
            aidedAnalyseService.submitResult(id);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("提交最终成果失败!", e);
            restResponse = RestResponse.fail("提交最终成果失败!");
        }
        return restResponse;
    }

    /**
     * 移除最终成果
     * @param id
     * @return
     */
    @PostMapping("/removeResult")
    public RestResponse removeResult(String id){
        RestResponse restResponse = null;
        try {
            aidedAnalyseService.removeResult(id);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("移除最终成果失败!", e);
            restResponse = RestResponse.fail("移除最终成果失败!");
        }
        return restResponse;
    }

    /**
     * 最终提交
     * @param ids
     * @return
     */
    @PostMapping("/finalSubmission/{ids}")
    public RestResponse finalSubmission(@PathVariable("ids") List<String> ids){
        RestResponse restResponse = null;
        try {
            aidedAnalyseService.finalSubmission(ids);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("最终提交失败!", e);
            restResponse = RestResponse.fail("最终提交失败!");
        }
        return restResponse;
    }
}
